﻿<section id="gallery">
    <div class="pics">
        @if (Model.HasValue("carouselImages")) {
            @* The carouselImages property stores some XML, which is automatically converted to DynamicXml for us here
                The root element for the stored XML is the <DAMP> node, so we have to look one level deeper to find the
                collection of Images in the <mediaItem> node). *@            
            dynamic mediaItems = Model.carouselImages.mediaItem;
            
            @* The DynamicXml "knows" it's looking at a collection of nodes, so they can be counted *@
            if (mediaItems.Count() != 0)
            {
                foreach (var item in mediaItems)
                {
                    @* "Image" is written with a capital "I" because that's how's it's defined in the XML *@
                    @* View the underlying XML like this: <pre>@item.ToXml()</pre> *@
                    var image = item.Image;                
                    @*
                        If the type of the mediacropper is not XML (but a string) then there 
                        are no crops defined, so I should not try to find the crops.
                    *@
                    var crops = image.mediaCropper;
                    if (crops.GetType().ToString() != "System.String")
                    {
                        <img src="@crops.Find("@name", "Homepage").url" alt="@image.nodeName" width="@image.umbracoWidth" height="@image.umbracoHeight"/><br />
                    }
                }
            }
        }        
    </div>
    <a href="#" id="prev"></a>
    <a href="#" id="next"></a>
</section>
<section id="intro">
    <div class="inner">
        <h2>@Html.Raw(Model.headerText)</h2>
        @Model.carouselText

        @if (Model.HasValue("readMoreLink")) 
        {
            var link = Model.readMoreLink;    
            @* In the original XML, there are some dashes, which not allowd in 
                method names, so they are stripped (new-window, link-title) 
                To have a look at the original XML, try: <pre>@Model.readMoreLink.ToXml()</pre> *@
            var target = link.newwindow == "True" ? "target=\"_blank\"" : "";   
            <a href="@link.url" class="extra-button" @target>@link.linktitle</a>
        }
    </div>
</section>


